<template>
	<view class="app">
		<authorize @onLoadFun="onLoadFun" isGoIndex></authorize>
		<view class="bg-img wallet-bg flex flex-direction align-center text-white ">
			<view class="text-grey total-text">总资产</view>
			<view class="">
				<text class="text-xsl">
					<text class="unit text-df">￥</text>
					{{ userInfo.account_balance || 0}}
				</text>
			</view>
		</view>
		<view class="app-container">
			<view class="card">
				<view class="text-bold">安全提示</view>
				<view>1. 平台不判断客户提供的收款账户真实性，收款账户的真实性、准确性由您确认，因收款账户、户名信息填写错误造成的退款，手续费不退回；</view>
				<view>2. 请妥善保管好您的微信个人信息安全</view>
			</view>
			<view class="card wallet-item">
				<view class="cu-list menu">
					<view class="cu-item">
						<view class="content text-default">
							<text class="cuIcon-warn"></text>
							<text class="">已到账</text>
						</view>
						<view class="action"><text class="text-gray">{{userInfo.arrive_balance}}</text></view>
					</view>
				</view>
			</view>
			<view class="card wallet-item">
				<view class="cu-list menu">
					<view class="cu-item" >
						<view class="content text-default">
							<text class="cuIcon-warn"></text>
							<text class="text-default">未到账</text>
						</view>
						<view class="action"><text class="text-gray">{{userInfo.not_arrive_balance}}</text></view>
					</view>
				</view>
			</view>
			<button class="cu-btn block box-shadow bg-primary margin-tb-sm lg" @tap="withdraw">提现</button>
		</view>
		<PaymentModal ref="PaymentModal" :showForget="showForget" :title="paymentModalTitle" v-model="payFlag" @confirm="confirmPassword"></PaymentModal>
	</view>
</template>

<script>
import Authorize from '@/components/authorize/authorize';
import PaymentModal from '@/components/payment-modal/password.vue';
import { getUserInfo, changePaymentCode } from '../api/user';
import { encrypt } from '../common/tools/encryption.js';
export default {
	components: {
		Authorize,
		PaymentModal
	},
	data() {
		return {
			itemStyle: {
				boxShadow: 0,
				border: '1px #172575 solid',
				width: '80rpx',
				height: '80rpx',
				lineHeight: '80rpx'
			},
			digitalList: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '', '0', '-1'], //键盘
			mode: null,
			password: '',
			paymentModalTitle: '',
			userInfo: {},
			payFlag: false,
			showForget: false
		};
	},
	methods: {
		onLoadFun() {
			this.getUserInfoEvent();
		},
		getUserInfoEvent() {
			return new Promise((resolve, reject) => {
				getUserInfo().then(res => {
					this.userInfo = res.result;
					resolve(res.result);
				});
			});
		},
		//提现
		withdraw() {
			this.checkPaymentCode
			this.payFlag = true;
			this.paymentModalTitle = this.userInfo.is_set_payment_code === 0 ? '设置安全密码' : '校验安全密码'
			this.showForget = this.userInfo.is_set_payment_code !== 0
		},
		hideModal() {
			this.$refs.PaymentModal.hideModal();
		},
		//输入密码后确认事件
		confirmPassword(value) {
			//设置安全密码
			if (this.userInfo.is_set_payment_code === 0) {
				//调接口
				changePaymentCode({
					payment_code: value
				}).then(res=> {
					this.userInfo.is_set_payment_code = 1;
					this.$refs.PaymentModal.hideModal();
					clearTimeout(this.timer);
					this.timer = setTimeout(() => {
						this.withdraw();
					}, 1000);
				}).catch(err => {
					this.$refs.PaymentModal.clear()
				})
			//校验安全密码
			} else {
				//调接口
				this.$refs.PaymentModal.hideModal();
				// 微信提现封印
				uni.showToast({
					icon: 'none',
					title: '微信提现功能正在建设中~(๑•̀ㅂ•́)و✧',
					duration: 6000
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.wallet-bg {
	background-image: url();
	width: 100%;
	height: 300rpx;
}
.total-text {
	color: #daddec;
}
.app-container {
	margin-top: -50rpx;
	.wallet-item.card {
		padding: 2px;
	}
}
</style>
